<template>
  <!-- <div>
      
    <form>
      标题
      <input type="text" name="title" v-model="title">
      <br>
      内容
      <textarea name="content"  cols="30" rows="10" placeholder="请输入内容" v-model="content"></textarea>
      <br>
      <button @click.prevent="submitForm">发表</button>
  
    </form>


  </div> -->

<form class="form-horizontal">

  <div class="form-group">
    <label for="inputTitle" class="col-sm-2 control-label">标题</label>
    <div class="col-sm-6">
      <input id="inputTitle" type="text" class="form-control" v-model="title" placeholder="标题">
    </div>

  </div>

  <div class="form-group">
    <label for="inputContent" class="col-sm-2 control-label">内容</label>
    <div class="col-sm-6">
      <textarea  id="inputContent" rows="5" class="form-control" v-model="content" placeholder="请输入帖子内容"></textarea>     
    </div>

  </div>
  

  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-1">
      <button @click.prevent="submitForm" class="btn btn-default">发布帖子</button>
    </div>
    
  </div>
  
</form>
</template>

<script>
export default {
  data(){
      return {
        title:"",
        content:"",  
      }
    },
  methods:{
    async submitForm(){
      try{
        let res = await this.$http.post("/api/addPost",{
          title:this.title,
          content:this.content,
        })
        this.$router.push("/posts/"+res.data.post.id)
      } catch(e){

        alert("没有登录，无法发帖")
      }

    }
  }

}

</script>
  
<style scoped>
  form{
    margin-top:100px;
  }
  
</style>
